//
// Created by 吴喆 on 2020/3/24.
//

#ifndef SUMMER_BULLET_H
#define SUMMER_BULLET_H


#include "Body.h"
#include "Playable.h"
#include "ParticleGenerator.h"

class Bullet : public Playable {
public:
    Bullet(const Scene *scene, Playable *parent, glm::vec2 startPosition);

    ~Bullet() override;

    /**
     * invoked while bullet touch the gameObject
     * @param gameObject gameObject which is touched
     */
    virtual void onTouched(GameObject *gameObject) = 0;

    /**
     * the bullet is over?
     */
    bool isOver = false;

    /**
     * the bullet contact?
     */
    bool isContacted = false;

    /**
     * the launch direction
     */
    glm::vec2 direction;

    /**
     * max range
     */
    float maxRange = 5.0f;

protected:
    /**
     * particle generator.
     */
    ParticleGenerator *particleGenerator = nullptr;

    /**
     * the object which launch the bullet
     */
    Playable *parent;

    /**
     * init
     */
    virtual void init();

    /**
     * set the particle generator
     */
    virtual void initParticleGenerator() {};

    /**
     * set the state machine
     */
    virtual void initStateMachine() = 0;

    /**
     * set b2box
     */
    void initBox() override;

    float rotate = 0.0f;
public:
    void update() override;
};

#endif //SUMMER_BULLET_H
